//
//  RelatedVideoTableViewCell.m
//  CYWFrame
//
//  Created by Macx on 2017/9/25.
//  Copyright © 2017年 Macx. All rights reserved.
//

#import "RelatedVideoTableViewCell.h"

#import "Articles.h"

@implementation RelatedVideoTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    CGFloat videoH = SW(5);
    CGFloat videoW = SW(7)*2;
    self.videoPic.frame = CGRectMake(SCREEN_WIDTH-videoW-10, 10, videoW, videoH);
    self.videoPic.contentMode = UIViewContentModeScaleAspectFill;
    self.videoPic.clipsToBounds = YES;
    
    self.title.font = kUHSystemFontWithSize(14);
    self.title.numberOfLines = 2;
    self.num.font = kUHSystemFontWithSize(12);
    self.time.font = kUHSystemFontWithSize(12);
    
    
    
}

- (void)setModel:(Articles *)model {
    
    if (_model != model) {
        _model = model;
        
        CGFloat videoW = SW(7)*2;;
        
        self.title.text = model.title;
        self.num.text = [NSString stringWithFormat:@"%ld评论", model.comments_count];
        self.time.text = model.human_time;
        
        [self.videoPic sd_setImageWithURL:[NSURL URLWithString:model.cover_url] placeholderImage:IMAGE(@"placeHolder")];
        
        CGSize size1 = [LZCTools textSizeWithText:@"字数" font:self.title.font];
        CGSize titleSize = [self.title.text sizeWithFont:kUHSystemFontWithSize(14) constrainedToSize:CGSizeMake(SCREEN_WIDTH-20-videoW, size1.height*10) lineBreakMode:NSLineBreakByWordWrapping];
        CGSize size2 = [LZCTools textSizeWithText:self.num.text font:self.num.font];
        
        self.title.frame = CGRectMake(10, 10, SCREEN_WIDTH-30-videoW, size1.height*2);

        CGFloat bottomY = self.videoPic.y+self.videoPic.height-size2.height;
        if (model.istop==1) {
            self.topBtn.frame = CGRectMake(self.title.x, bottomY-1, 20, size2.height+2);
        }
        else {
            self.topBtn.frame = CGRectMake(self.title.x, bottomY-1, 0, size2.height+2);
        }
        self.num.frame = CGRectMake(self.topBtn.x+self.topBtn.width+10, bottomY, size2.width, size2.height);
        self.time.frame = CGRectMake(self.num.x+self.num.width+10, bottomY, SW(2), size2.height);
        
        self.height = self.num.y+self.num.height+10;
        
    }
}

- (CGFloat)cellHeight {
    
    //    return self.sepView.y+self.sepView.height;
    return self.height;
    
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
